package com.lucy.viewer.viewerjs.provider;

import com.lucy.viewer.constant.ViewerServiceEnum;
import com.lucy.viewer.params.ViewerFile;
import com.lucy.viewer.service.ViewerFileService;
import com.lucy.viewer.service.ViewerService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * @author kindear
 * viewerjs 服务实现
 */
@Slf4j
@Service
@AllArgsConstructor
public class ViewerJsViewerServiceImpl implements ViewerService {
    ViewerFileService viewerFileService;

    @Override
    public ViewerServiceEnum service() {
        return ViewerServiceEnum.VIEWER_JS;
    }

    @Override
    public ModelAndView loadPreviewView(String documentKey, HttpServletResponse response) throws IOException {
        ViewerFile viewerFile = viewerFileService.getViewerFile(documentKey);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("imgviewer");
        modelAndView.addObject("file",viewerFile);
        return modelAndView;
    }

    @Override
    public ModelAndView loadEditorView(String documentKey, HttpServletResponse response) throws IOException {
        // 直接以预览形式呈现
        return loadPreviewView(documentKey,response);
    }

    @Override
    public Object editorCallBack(Map<String, Object> map) {
        throw new RuntimeException("不支持图片格式在线修改");
    }
}
